package edu.fiu.cs.kdrg.sql.syntax.tree;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;

import edu.fiu.cs.kdrg.sql.util.XTree;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.statement.Statement;

public class TestSyntaxTreeVisitor {
	
	public static void testSelect() throws JSQLParserException, IOException{
		String query = "SELECT COUNT(*) FROM `SKEWED_VALUES`, T THIS WHERE THIS.`SD_ID_OID`=23 AND THIS.`INTEGER_IDX`>=0";
		CCJSqlParserManager pm = new CCJSqlParserManager();
		Statement stmt = pm.parse(new StringReader(query));
		SyntaxTreeVisitor visitor = new SyntaxTreeVisitor();
		Node root = stmt.nodeAccept(visitor);
		FileOutputStream out = new FileOutputStream("xtree.xml");
		XTree.TreeSerialize(root,out);
		out.close();
	}

	public static void main(String[] args) throws JSQLParserException, IOException {
		// TODO Auto-generated method stub
		testSelect();
		
	}

}
